package com.juku2024.juku.db.converter

import android.text.TextUtils
import androidx.room.TypeConverter
import com.juku2024.juku.model.LimitModel
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken

class LimitConverters {

    @TypeConverter
    fun stringToList(value: String?): LimitModel? {
        return if (TextUtils.isEmpty(value)) {
            null
        } else {
            val listType = object : TypeToken<LimitModel>() {}.type
            Gson().fromJson(value, listType)
        }

    }

    @TypeConverter
    fun listToString(list: LimitModel?): String? {
        return if (list != null) {
            Gson().toJson(list)
        } else {
            null
        }
    }

}